<!--
 * @页面名称:移交下一环节
 * @描述: 
 * @作者: 
 * @Date:
-->
<template>
  <el-dialog v-model="handoverSetting.visible" :title="handoverSetting.title" width="30%" draggable>
    <stable height="300" :columns="columns" :data="handoverSetting.data"></stable>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="handoverSetting.visible = false">取消</el-button>
        <el-button type="primary" @click="handoverHandle"> 确定 </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref } from "vue";
import { formatter, submit } from "./index";
import { useDynamicStore } from "@/stores/modules/dynamic";
import { useRoute } from "vue-router";
import useCurrentInstance from "@/utils/useCurrentInstance";

const props = defineProps({
  handoverSetting: {
    type: Object,
    default: () => {
      return {};
    }
  }
});
const { proxy } = useCurrentInstance();
const route = useRoute();
// 获取pinia数据
const dynamicStore = useDynamicStore();
// 获取路由
// 移交下一环节配置
const columns = [
  { title: "档号", field: "Code", sortable: true },
  { title: "标题", field: "Title", sortable: true, formatter: formatter }
];
// 移交下一环节弹框确认事件
const handoverHandle = () => {
  props.handoverSetting.visible = false;
  if (props.handoverSetting.type === "parent") {
    const tableName = dynamicStore.visibleConfig.FMT.FMT_TableName;
    submit(props.handoverSetting.data, props.handoverSetting.StatusValue, props.handoverSetting.openStatus, tableName).then(
      (res: any) => {
        // 改变本地数据
        dynamicStore.childTableData = [];
      }
    );
  } else if (props.handoverSetting.type === "child") {
    const tableName = dynamicStore.childVisibleConfig.FMT.FMT_TableName;
    switch (route.query.status) {
      case "Collect":
        if (props.handoverSetting.retreat) {
          //表示收集阶段是不可以退回的
          return;
        } else {
          submit(props.handoverSetting.data, 2, tableName).then((res: any) => {
            // 改变本地数据
            dynamicStore.childTableData = [];
          });
        }
        break;
      case "Arrangement":
        if (props.handoverSetting.retreat) {
          retreatSubmit(props.handoverSetting.data, 5, tableName).then(res => {
            // 改变本地数据
            dynamicStore.childTableData = [];
          });
          return;
        } else {
          submit(props.handoverSetting.data, 3, tableName).then((res: any) => {
            // 改变本地数据
            dynamicStore.childTableData = [];
          });
        }
        break;
      case "Storage":
        if (props.handoverSetting.retreat) {
          retreatSubmit(props.handoverSetting.data, 6, tableName).then(res => {
            // 改变本地数据
            dynamicStore.childTableData = [];
          });
          return;
        } else {
          submit(props.handoverSetting.data, 4, tableName).then((res: any) => {
            // 改变本地数据
            dynamicStore.childTableData = [];
          });
        }
        break;
      case "Utilization":
        if (props.handoverSetting.retreat) {
          retreatSubmit(props.handoverSetting.data, 7, tableName).then(res => {
            // 改变本地数据
            dynamicStore.childTableData = [];
          });
          return;
        }
        break;
    }
  }
};
</script>

<style scoped></style>
